// 命名空间
var activity = {};
// 所有代码
activity.mainPath = 'modules/main/activity/';
activity.srcPath = activity.mainPath + 'src/';
activity.src = [
    activity.srcPath + 'NewCoinShopWindow/ProtobufferTables.js',
    activity.srcPath + 'NewCoinShopWindow/NewCoinShopCfg.js',
    activity.srcPath + 'NewCoinShopWindow/NewCoinShopWindow.js',
    activity.srcPath + 'NewCoinShopWindow/NewCoinShopCellItem.js',
    activity.srcPath + 'NewCoinShopWindow/NewCoinShopRecordWindow.js',
    activity.srcPath + 'NewCoinShopWindow/NewCoinShopRecordCellItem.js',
    activity.srcPath + 'NewCoinShopWindow/NewCoinShopPayWindow.js',

    activity.srcPath + 'zhounianqing/CommonView.js',
    activity.srcPath + 'zhounianqing/HomeLayer.js',
    activity.srcPath + 'zhounianqing/YureLayer.js',

];

// 所有资源
activity.resPath = activity.mainPath + 'res/';
activity.res = {
    NewCoinShopWindow_json: activity.mainPath + 'res/NewCoinShopWindow.json',
    NewCoinShopCellUnit_json: activity.mainPath + 'res/NewCoinShopCellUnit.json',
    NewCoinShopRecordCellUnit_json: activity.mainPath + 'res/NewCoinShopRecordCellUnit.json',
    NewCoinShopPayWindow_json: activity.mainPath + 'res/NewCoinShopPayWindow.json',
    NewCoinShopRecordWindow_json: activity.mainPath + 'res/NewCoinShopRecordWindow.json'


    , znq_ShareLayer: activity.mainPath + "res/activity/zhounianqing/ShareLayer.json"
    , znq_ShareRedLayer: activity.mainPath + "res/activity/zhounianqing/ShareRedLayer.json"
    , znq_RuleLayer: activity.mainPath + "res/activity/zhounianqing/RuleLayer.json"
    , znq_ReceiveRuleLayer: activity.mainPath + "res/activity/zhounianqing/ReceiveRuleLayer.json"
    , znq_HomeLayer: activity.mainPath + "res/activity/zhounianqing/HomeLayer.json"
    , znq_YureLayer: activity.mainPath + "res/activity/zhounianqing/YureLayer.json"
    , znq_ShareNodeJson: activity.mainPath + "res/activity/zhounianqing/ShareNode.json"
    , sp_zhounianqing_json: activity.mainPath + "res/activity/zhounianqing/zhounianqing.json"
    , sp_zhounianqing_atlas: activity.mainPath + "res/activity/zhounianqing/zhounianqing.atlas"
    , sp_zhounianqing_png: activity.mainPath + "res/activity/zhounianqing/zhounianqing.png"
    , sp_zhounian_hongbao_json: activity.mainPath + "res/activity/zhounian_hongbao/zhounian_hongbao.json"
    , sp_zhounian_hongbao_atlas: activity.mainPath + "res/activity/zhounian_hongbao/zhounian_hongbao.atlas"
    , sp_zhounian_hongbao_png: activity.mainPath + "res/activity/zhounian_hongbao/zhounian_hongbao.png"

};

//首次弹窗控制
activity.isShowPopFirst = true;
activity.isShowFirst = true;
activity.isShowFirstNative = true;

//弹窗方法
activity.popWindow = function () {
    if (gameData.opt_conf_2["ZNQYR"] > 0 && activity.isShowPopFirst) {
        var yure = new YureLayer();
        window.curScene.addChild(yure, ZORDER.DIALOG);
        activity.isShowPopFirst = false;
    }
};
activity.popWebView = function (btn_activity) {
    //端内活动
    if (gameData.opt_conf_2["ZNQHD"] > 0) {
        if (btn_activity) {
            btn_activity.setVisible(true)
            TouchUtil.setOnclickListener(btn_activity, function () {
                window.curScene.addChild(new HomeLayer(), ZORDER.WINDOW);
            });
            var emoji = playSpine(res.sp_zhounianqing_json, undefined, true, function () {

            })
            emoji.setPosition(cc.p(btn_activity.getContentSize().width / 2, btn_activity.getContentSize().height / 2));
            btn_activity.addChild(emoji);
        }
        if (activity.isShowFirstNative) {
            activity.isShowFirstNative = false;
            window.curScene.addChild(new HomeLayer(), ZORDER.WINDOW);
        }
    }
};
/**
 * 总结算活动接口
 * @param area
 * @param roomid
 * @param uid
 * @param data 总结算数据 预留
 */
activity.gameOverCallback = function (area, roomid, uid, data) {
    if (!area || !roomid) {
        console.log('房间号 地区不能为空');
        return;
    }
    var boxUrl = null;
    if (gameData.opt_conf_2["ZNQHD"] == 1) {
        boxUrl = 'http://pay.yayayouxi.com/fyactivity/app/gameOverMessage';
    } else if (gameData.opt_conf_2["ZNQHD"] == 2) {
        boxUrl = "http://pay.yayayouxi.com/fyactivity-test/app/gameOverMessage"
    }
    if (!boxUrl) {
        console.log("服务器元旦活动未开启");
        return;
    }
    showLoading('正在请求中...')
    var data = {
        'playerId': uid,
        'roomId': roomid,
        'area': area,
        'activityType': 55,
        'signKey': Crypto.MD5("feiyu-activity" + roomid + area)
    }
    cc.log(JSON.stringify(data));
    http.post(boxUrl, data,
        function (data) {
            hideLoading();
            cc.log(JSON.stringify(data));
            if (data.code == '0000') {
                var playerArr = data.data;
                for (var i = 0; i < playerArr.length; i++) {
                    var info = playerArr[i]
                    if (info.playerId == gameData.uid && info.drawType > 0) {
                        var layer = new cc.Layer();
                        cc.director.getRunningScene().addChild(layer, 99999);
                        var spNode = playSpine(res.sp_zhounian_hongbao_json, undefined, true, function () {

                        })
                        TouchUtil.setOnclickListener(layer, function () {
                            layer.removeFromParent()
                        });
                        spNode.setPosition(cc.p(cc.winSize.width / 2, cc.winSize.height / 2));
                        layer.addChild(spNode);
                        break;
                    }
                }
            } else {
            }
        }, function (reqdata) {
            hideLoading();
            cc.log(JSON.stringify(reqdata));
        }
    );
}